package org.iabako.client.ui.form.business.sale.make;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import org.iabako.client.ui.layout.field.Button;
import org.iabako.client.ui.layout.field.LabelText;
import org.iabako.client.ui.layout.widget.validation.ValidationMessage;

/**
 * Created by jose on 22/10/14.
 */
public abstract class SaleMakeSubForm extends Composite {

    @UiField
    Button goAhead;
    @UiField
    Button goBack;

    SaleMakeForm saleMakeForm;

    public void setSaleMakeForm(SaleMakeForm saleMakeForm) {
        this.saleMakeForm = saleMakeForm;
    }

    protected void setDefaultHandlers() {
        setGoAheadHandler();
        setGoBackHandler();
    }

    private void setGoAheadHandler() {
        goAhead.getButton().addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                ValidationMessage.getFirstFromDOM().clear();
                validateForm();
            }
        });
    }

    protected abstract void validateForm();

    private void setGoBackHandler() {
        goBack.getButton().addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                ValidationMessage.getFirstFromDOM().clear();
                goBackAction();
            }
        });
    }

    protected abstract void goBackAction();

    protected abstract void restoreDraft();
}
